/*
 * ZlorfBasicView.java
 *
 * Created on 27 March 2008, 18:35
 */
package org.zlorf.view;

import com.sun.jna.NativeLibrary;
import java.awt.Color;
import java.beans.PropertyVetoException;
import java.util.Set;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import javax.swing.JFrame;
import javax.swing.JToggleButton;
import org.slf4j.LoggerFactory;
import org.zlorf.controller.MainController;
import org.zlorf.view.options.OptionsForm;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.runtime.windows.WindowsRuntimeUtil;

/**
 *
 * @author  Mat Jaggard
 */
public class ZlorfBasicView extends JFrame
{

	private static final long serialVersionUID = 1L;
	private MediaPlayerFactory mediaPlayerFactory;
	private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(ZlorfBasicView.class);
	private MainController main = new MainController();

	/** Creates new form ZlorfBasicView */
	public ZlorfBasicView()
	{
		this.setTitle("Zlorf Control");
		initComponents();
		leftSplitPane.setDividerLocation(0.3333333d);
		leftSplitPane.setResizeWeight(0.333333333d);
		rightSplitPane.setDividerLocation(0.5d);
		rightSplitPane.setResizeWeight(0.5d);

		String[] vlcArgs = new String[1];
		if (RuntimeUtil.isWindows())
		{
			NativeLibrary.addSearchPath("libvlc", WindowsRuntimeUtil.getVlcInstallDir());
			vlcArgs[0] = "--plugin-path=" + WindowsRuntimeUtil.getVlcInstallDir() + "\\plugins";
		}
		mediaPlayerFactory = new MediaPlayerFactory(vlcArgs);
		main.addDisplay(previewPanel);
		main.setupDisplays(this);
	}

	public RenderArea createPreview()
	{
		JMainPanel toReturn = new JMainPanel("Full Screen Preview");
		toReturn.setVisible(true);
		toReturn.setBackground(Color.BLACK);
		return toReturn;
	}

	/*
	public void playVideo(Set<RenderArea> ras)
	{
		for (RenderArea ra : ras)
		{
			if (ra instanceof VLCHolder)
			{
				VLCHolder vlch = (VLCHolder) ra;
				boolean working = vlch.addVLC(mediaPlayerFactory);
				if (!working)
				{
					LOG.error("Could not create VLC on the main screen preview window.");
				}
				else
				{
					EmbeddedMediaPlayer mediaPlayer = vlch.getMediaPlayer();
					if (mediaPlayer == null)
					{
						LOG.error("The Media Player created is set to null.");
					}
					else
					{
						mediaPlayer.playMedia("file:///c:/YourLoveNeverFails.flv");
					}
				}
			}
		}
	}
*/

	/** This method is called from within the constructor to
	 * initialise the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        leftSplitPane = new javax.swing.JSplitPane();
        rightSplitPane = new javax.swing.JSplitPane();
        oosItemAreaPane = new javax.swing.JPanel();
        displayAreaPane = new javax.swing.JPanel();
        displayPreviewAreaPane = new javax.swing.JPanel();
        toggleButtonPanel = new javax.swing.JPanel();
        toggleFrozen = new javax.swing.JToggleButton();
        toggleBlank = new javax.swing.JToggleButton();
        toggleStop = new javax.swing.JToggleButton();
        previewPanel = new org.zlorf.view.JPreviewPanel();
        newItemPane = new javax.swing.JTabbedPane();
        newVLCItemPane = new javax.swing.JPanel();
        newSongItemPane = new javax.swing.JPanel();
        newBibleVerseItemPane = new javax.swing.JPanel();
        oosScrollPane = new javax.swing.JScrollPane();
        oosPanel = new javax.swing.JPanel();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        newMenuItem = new javax.swing.JMenuItem();
        openMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        saveAsMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        editMenu = new javax.swing.JMenu();
        cutMenuItem = new javax.swing.JMenuItem();
        copyMenuItem = new javax.swing.JMenuItem();
        pasteMenuItem = new javax.swing.JMenuItem();
        deleteMenuItem = new javax.swing.JMenuItem();
        toolsMenu = new javax.swing.JMenu();
        optionsMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/zlorf/view/UserInterfaceBundle"); // NOI18N
        setTitle(bundle.getString("ZlorfBasicView.title.text")); // NOI18N
        setName("Form"); // NOI18N
        getContentPane().setLayout(new java.awt.GridLayout(1, 3));

        leftSplitPane.setName("leftSplitPane"); // NOI18N

        rightSplitPane.setName("rightSplitPane"); // NOI18N

        oosItemAreaPane.setName("oosItemAreaPane"); // NOI18N

        javax.swing.GroupLayout oosItemAreaPaneLayout = new javax.swing.GroupLayout(oosItemAreaPane);
        oosItemAreaPane.setLayout(oosItemAreaPaneLayout);
        oosItemAreaPaneLayout.setHorizontalGroup(
            oosItemAreaPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        oosItemAreaPaneLayout.setVerticalGroup(
            oosItemAreaPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 432, Short.MAX_VALUE)
        );

        rightSplitPane.setLeftComponent(oosItemAreaPane);

        displayAreaPane.setName("displayAreaPane"); // NOI18N
        displayAreaPane.setLayout(new java.awt.GridLayout(2, 1));

        displayPreviewAreaPane.setName("displayPreviewAreaPane"); // NOI18N
        displayPreviewAreaPane.setLayout(new java.awt.BorderLayout());

        toggleButtonPanel.setName("toggleButtonPanel"); // NOI18N

        toggleFrozen.setText(bundle.getString("ZlorfBasicView.toggleFrozen.label")); // NOI18N
        toggleFrozen.setName("toggleFrozen"); // NOI18N
        toggleButtonPanel.add(toggleFrozen);

        toggleBlank.setText(bundle.getString("ZlorfBasicView.toggleBlank.label")); // NOI18N
        toggleBlank.setName("toggleBlank"); // NOI18N
        toggleBlank.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                toggleBlankActionPerformed(evt);
            }
        });
        toggleButtonPanel.add(toggleBlank);

        toggleStop.setText(bundle.getString("ZlorfBasicView.toggleStop.text")); // NOI18N
        toggleStop.setName("toggleStop"); // NOI18N
        toggleStop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                toggleStopActionPerformed(evt);
            }
        });
        toggleButtonPanel.add(toggleStop);

        displayPreviewAreaPane.add(toggleButtonPanel, java.awt.BorderLayout.NORTH);

        previewPanel.setBackground(new java.awt.Color(0, 0, 0));
        previewPanel.setDoubleBuffered(false);
        previewPanel.setName("previewPanel"); // NOI18N

        javax.swing.GroupLayout previewPanelLayout = new javax.swing.GroupLayout(previewPanel);
        previewPanel.setLayout(previewPanelLayout);
        previewPanelLayout.setHorizontalGroup(
            previewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 244, Short.MAX_VALUE)
        );
        previewPanelLayout.setVerticalGroup(
            previewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 183, Short.MAX_VALUE)
        );

        displayPreviewAreaPane.add(previewPanel, java.awt.BorderLayout.CENTER);

        displayAreaPane.add(displayPreviewAreaPane);

        newItemPane.setName("newItemPane"); // NOI18N

        newVLCItemPane.setName("newVLCItemPane"); // NOI18N

        javax.swing.GroupLayout newVLCItemPaneLayout = new javax.swing.GroupLayout(newVLCItemPane);
        newVLCItemPane.setLayout(newVLCItemPaneLayout);
        newVLCItemPaneLayout.setHorizontalGroup(
            newVLCItemPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 800, Short.MAX_VALUE)
        );
        newVLCItemPaneLayout.setVerticalGroup(
            newVLCItemPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 191, Short.MAX_VALUE)
        );

        newItemPane.addTab(bundle.getString("ZlorfBasicView.newVLCItemPane.TabConstraints.tabTitle"), newVLCItemPane); // NOI18N

        newSongItemPane.setName("newSongItemPane"); // NOI18N

        javax.swing.GroupLayout newSongItemPaneLayout = new javax.swing.GroupLayout(newSongItemPane);
        newSongItemPane.setLayout(newSongItemPaneLayout);
        newSongItemPaneLayout.setHorizontalGroup(
            newSongItemPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 800, Short.MAX_VALUE)
        );
        newSongItemPaneLayout.setVerticalGroup(
            newSongItemPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 191, Short.MAX_VALUE)
        );

        newItemPane.addTab(bundle.getString("ZlorfBasicView.newSongItemPane.TabConstraints.tabTitle"), newSongItemPane); // NOI18N

        newBibleVerseItemPane.setName("newBibleVerseItemPane"); // NOI18N

        javax.swing.GroupLayout newBibleVerseItemPaneLayout = new javax.swing.GroupLayout(newBibleVerseItemPane);
        newBibleVerseItemPane.setLayout(newBibleVerseItemPaneLayout);
        newBibleVerseItemPaneLayout.setHorizontalGroup(
            newBibleVerseItemPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 800, Short.MAX_VALUE)
        );
        newBibleVerseItemPaneLayout.setVerticalGroup(
            newBibleVerseItemPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 191, Short.MAX_VALUE)
        );

        newItemPane.addTab(bundle.getString("ZlorfBasicView.newBibleVerseItemPane.TabConstraints.tabTitle"), newBibleVerseItemPane); // NOI18N

        displayAreaPane.add(newItemPane);

        rightSplitPane.setRightComponent(displayAreaPane);

        leftSplitPane.setRightComponent(rightSplitPane);
        rightSplitPane.setDividerLocation(0.5);

        oosScrollPane.setName("oosScrollPane"); // NOI18N

        oosPanel.setBackground(new java.awt.Color(255, 255, 255));
        oosPanel.setName("oosPanel"); // NOI18N

        javax.swing.GroupLayout oosPanelLayout = new javax.swing.GroupLayout(oosPanel);
        oosPanel.setLayout(oosPanelLayout);
        oosPanelLayout.setHorizontalGroup(
            oosPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 261, Short.MAX_VALUE)
        );
        oosPanelLayout.setVerticalGroup(
            oosPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 436, Short.MAX_VALUE)
        );

        oosScrollPane.setViewportView(oosPanel);

        leftSplitPane.setLeftComponent(oosScrollPane);

        getContentPane().add(leftSplitPane);
        leftSplitPane.setDividerLocation(0.5);

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(bundle.getString("ZlorfBasicView.fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        newMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        newMenuItem.setText(bundle.getString("ZlorfBasicView.newMenuItem.text")); // NOI18N
        newMenuItem.setName("newMenuItem"); // NOI18N
        fileMenu.add(newMenuItem);

        openMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        openMenuItem.setText(bundle.getString("ZlorfBasicView.openMenuItem.text")); // NOI18N
        openMenuItem.setName("openMenuItem"); // NOI18N
        fileMenu.add(openMenuItem);

        saveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        saveMenuItem.setText(bundle.getString("ZlorfBasicView.saveMenuItem.text")); // NOI18N
        saveMenuItem.setName("saveMenuItem"); // NOI18N
        fileMenu.add(saveMenuItem);

        saveAsMenuItem.setText(bundle.getString("ZlorfBasicView.saveAsMenuItem.text")); // NOI18N
        saveAsMenuItem.setName("saveAsMenuItem"); // NOI18N
        saveAsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveAsMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveAsMenuItem);

        exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        exitMenuItem.setText(bundle.getString("ZlorfBasicView.exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        editMenu.setText(bundle.getString("ZlorfBasicView.editMenu.text")); // NOI18N
        editMenu.setName("editMenu"); // NOI18N

        cutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        cutMenuItem.setText(bundle.getString("ZlorfBasicView.cutMenuItem.text")); // NOI18N
        cutMenuItem.setName("cutMenuItem"); // NOI18N
        editMenu.add(cutMenuItem);

        copyMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        copyMenuItem.setText(bundle.getString("ZlorfBasicView.copyMenuItem.text")); // NOI18N
        copyMenuItem.setName("copyMenuItem"); // NOI18N
        editMenu.add(copyMenuItem);

        pasteMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        pasteMenuItem.setText(bundle.getString("ZlorfBasicView.pasteMenuItem.text")); // NOI18N
        pasteMenuItem.setName("pasteMenuItem"); // NOI18N
        editMenu.add(pasteMenuItem);

        deleteMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, 0));
        deleteMenuItem.setText(bundle.getString("ZlorfBasicView.deleteMenuItem.text")); // NOI18N
        deleteMenuItem.setName("deleteMenuItem"); // NOI18N
        editMenu.add(deleteMenuItem);

        menuBar.add(editMenu);

        toolsMenu.setText(bundle.getString("ZlorfBasicView.toolsMenu.text")); // NOI18N
        toolsMenu.setName("toolsMenu"); // NOI18N

        optionsMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        optionsMenuItem.setText(bundle.getString("ZlorfBasicView.optionsMenuItem.text")); // NOI18N
        optionsMenuItem.setName("optionsMenuItem"); // NOI18N
        optionsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                optionsMenuItemActionPerformed(evt);
            }
        });
        toolsMenu.add(optionsMenuItem);

        menuBar.add(toolsMenu);

        setJMenuBar(menuBar);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void toggleBlankActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_toggleBlankActionPerformed
		try
		{
			main.blankButton(((JToggleButton) evt.getSource()).isSelected());
		}
		catch (PropertyVetoException pve)
		{
			LOG.error("The blank button was vetoed but the view doesn't support that.", pve);
		}
}//GEN-LAST:event_toggleBlankActionPerformed

    private void optionsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_optionsMenuItemActionPerformed
		OptionsForm of = new OptionsForm();
		of.setVisible(true);
}//GEN-LAST:event_optionsMenuItemActionPerformed

		private void exitMenuItemActionPerformed (java.awt.event.ActionEvent evt)//GEN-FIRST:event_exitMenuItemActionPerformed
		{//GEN-HEADEREND:event_exitMenuItemActionPerformed
			System.exit(0);
		}//GEN-LAST:event_exitMenuItemActionPerformed

                private void saveAsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsMenuItemActionPerformed
					// TODO add your handling code here:
                }//GEN-LAST:event_saveAsMenuItemActionPerformed

				private void toggleStopActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_toggleStopActionPerformed
				{//GEN-HEADEREND:event_toggleStopActionPerformed
					// TODO add your handling code here:
				}//GEN-LAST:event_toggleStopActionPerformed

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[])
	{
		java.awt.EventQueue.invokeLater(new Runnable()
		{

			public void run()
			{
				new ZlorfBasicView().setVisible(true);
			}
		});
	}
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem copyMenuItem;
    private javax.swing.JMenuItem cutMenuItem;
    private javax.swing.JMenuItem deleteMenuItem;
    private javax.swing.JPanel displayAreaPane;
    private javax.swing.JPanel displayPreviewAreaPane;
    private javax.swing.JMenu editMenu;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JSplitPane leftSplitPane;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JPanel newBibleVerseItemPane;
    private javax.swing.JTabbedPane newItemPane;
    private javax.swing.JMenuItem newMenuItem;
    private javax.swing.JPanel newSongItemPane;
    private javax.swing.JPanel newVLCItemPane;
    private javax.swing.JPanel oosItemAreaPane;
    private javax.swing.JPanel oosPanel;
    private javax.swing.JScrollPane oosScrollPane;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JMenuItem optionsMenuItem;
    private javax.swing.JMenuItem pasteMenuItem;
    private org.zlorf.view.JPreviewPanel previewPanel;
    private javax.swing.JSplitPane rightSplitPane;
    private javax.swing.JMenuItem saveAsMenuItem;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JToggleButton toggleBlank;
    private javax.swing.JPanel toggleButtonPanel;
    private javax.swing.JToggleButton toggleFrozen;
    private javax.swing.JToggleButton toggleStop;
    private javax.swing.JMenu toolsMenu;
    // End of variables declaration//GEN-END:variables
}
